package com.jdk.demo.queue.arrayBlockingQueue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

public class Producer implements Runnable {

	private  BlockingQueue<String> blockingQueue;
	private static int element = 0;

	public Producer(BlockingQueue<String> blockingQueue) {
		this.blockingQueue = blockingQueue;
	}

	public void run() {
		try {
			while(element < 20) {
				System.out.println("将要放进去的元素是：" + element);
				// blockingQueue.put("data:" + element++);
				// blockingQueue.add("data:" + element++);
				blockingQueue.offer("data:" + element++, 100, TimeUnit.MICROSECONDS);
			}
		} catch (Exception e) {
			System.out.println("生产者在等待空闲空间的时候被打断了！");
			e.printStackTrace();
		}
		System.out.println("生产者已经终止了生产过程！");
	}

}
